package com.example.dllo.baidumusic.fragment;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.adapter.LineAdapter;
import com.example.dllo.baidumusic.bean.LineBean;
import com.example.dllo.baidumusic.nettool.URLValuas;
import com.example.dllo.baidumusic.main.NewActivity;
import com.example.dllo.baidumusic.nettool.BaseFragment;
import com.example.dllo.baidumusic.nettool.NetTool;

/**
 * Created by dllo on 16/8/15.
 */
public class LineFragment extends BaseFragment {
    private ListView lv;
    private LineAdapter adapter;
    private LineBean lineBean;

    @Override
    protected int setLayout() {
        return R.layout.fragment_line;
    }

    @Override
    protected void initView() {
        lv = bindView(R.id.line_fragment_listview);


    }

    @Override
    protected void initData() {
        adapter = new LineAdapter(getContext());
        final NetTool netTool = new NetTool();
        netTool.getNetData(URLValuas.MUSICSTORE_TOP, LineBean.class, new NetTool.NetListener<LineBean>() {
            @Override
            public void onSuccess(LineBean lineBean) {

                adapter.setLineBeen(lineBean);
                lv.setAdapter(adapter);
                UpData(lineBean);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });

    }
    private void UpData(final LineBean lineBean){
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String string = lineBean.getContent().get(position).getType();
                String URL = URLValuas.TOP_SONG_FRONT + string + URLValuas.TOP_SONG_BEHIND;
                NewSingFragment newSingFragment = new NewSingFragment();
                Bundle bundle = new Bundle();
                bundle.putString("sing",URL);
                newSingFragment.setArguments(bundle);
                NewActivity.getManager(newSingFragment);

            }
        });
    }
}
